package com.example.stock.business.monitor.logic;

import com.example.stock.excel.Monitor;
import com.example.stock.model.WeekDetail;
import com.example.stock.service.WeekDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 周涨跌统计
 */
@Component
public class WeekPctMonitor implements Trigger{

    @Autowired
    WeekDataService weekDataService;

    @Override
    public boolean trigger(Monitor monitor) {
        WeekDetail currentWeekDetail = weekDataService.getCurrentWeekDetail(monitor.getStock());
        if (currentWeekDetail == null) {
            return false;
        }

        double m = Double.parseDouble(monitor.getExtra());

        return switch (monitor.getCategory()) {
            case "小于" -> currentWeekDetail.getWeekPct() <= m;
            case "大于" -> currentWeekDetail.getWeekPct() >= m;
            case "DE_SUM" -> currentWeekDetail.getPctSum() < m;
            default -> false;
        };
    }
}